package com.idealighter.game.chat.manager;

import com.google.inject.Inject;
import com.google.inject.Singleton;

import com.idealighter.game.chat.message.ResHornMsg;
import com.idealighter.game.chat.message.ResRoomChatMsg;
import com.idealighter.game.chat.message.ResSysNoticeMsg;
import com.idealighter.game.chat.message.ResTableChatMsg;
import com.idealighter.game.player.manager.PlayerMsgWriter;
import com.idealighter.game.player.struct.Player;

/**
 * 聊天消息管理 .
 * 
 * @date 2015年11月13日 下午2:09:19
 *
 */
@Singleton
public class ChatMsgMgr {
  @Inject
  private PlayerMsgWriter msgWriter;

  /**
   * 发送房间聊天消息 .
   * 
   * @param player 玩家.
   * @param content .
   */
  public void sendRoomChatMsg(Player player, String content) {
    ResRoomChatMsg msg = new ResRoomChatMsg();
    msg.setContent(content);
    msg.setPlayerName(player.getPlayerName());

    for (Long target : player.curRoom.getPlayers()) {
      msgWriter.writeMsg(target, msg);
    }
  }

  /**
   * 发送桌子聊天消息 .
   * 
   * @param player 玩家.
   * @param content .
   */
  public void sendTableChatMsg(Player player, String content) {
    ResTableChatMsg msg = new ResTableChatMsg();
    msg.setContent(content);
    msg.setPlayerName(player.getPlayerName());

    for (Long target : player.curTable.players()) {
      msgWriter.writeMsg(target, msg);
    }
  }

  /**
   * 发送喇叭消息 .
   * 
   * @param playerName .
   * @param content .
   */
  public void sendHornMsg(String playerName, String content) {
    ResHornMsg msg = new ResHornMsg();
    msg.setPlayerName(playerName);
    msg.setContent(content);

    msgWriter.writeWorld(msg);
  }

  /**
   * 发送聊天框系统公告消息 .
   * 
   * @param content .
   */
  public void sendSysNoticeMsg(String content) {
    ResSysNoticeMsg msg = new ResSysNoticeMsg();
    msg.setContent(content);

    msgWriter.writeWorld(msg);
  }

}
